package com.wondersgroup.app.appointment.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wondersgroup.core.frame.BaseController;
import com.wondersgroup.core.frame.CommonStatusResult;
import com.wondersgroup.core.model.Company;
import com.wondersgroup.core.resultmap.DTOSearchCompanyRode;
import com.wondersgroup.core.service.CompanyService;
import com.wondersgroup.core.service.SearchCompanyRodeService;
import com.wondersgroup.core.util.ErrorMessageConstant;

@Controller
@RequestMapping("/company")
public class SearchCompanyRodeController extends BaseController{

	@Resource
	private SearchCompanyRodeService searchCompanyRodeService;

	/*
	 * 获取商品出厂公司
	 * 
	 *根据公司ID 产品批次号 产品唯一标识条码 查询 追溯信息
	 */
	@RequestMapping(value = "searchRode", method = RequestMethod.POST)
	@ResponseBody
	public CommonStatusResult searchCompanyRode(
			@RequestParam(value = "companyId", required = true) String companyId,//公司Id
			@RequestParam(value = "barcode", required = true) String barcode,//产品唯一条码
			@RequestParam(value = "batchNo", required = true) String batchNo) {//产品批次号

		if (barcode !=null && !barcode.equals("") &&
			batchNo != null && !batchNo.equals("")&& 
			companyId != null && !companyId.equals("")){
			 List<DTOSearchCompanyRode> list= searchCompanyRodeService.searchCompanyRode(companyId, barcode, batchNo);
			 if(list.size() !=0 && list !=null){
					return CommonStatusResult.success(ErrorMessageConstant.CODE_SUCCESS, list);
			 }
			 return CommonStatusResult.fail(ErrorMessageConstant.CODE_FAIL, null);
		}

		return CommonStatusResult.fail(ErrorMessageConstant.CODE_FAIL, null);
	}
}
